<?php
class Municipalities_model extends Model {

    function getAllMunicipalities($langid) {
        $query = $this->db->get_where('municipalities', array('municipality_lang' => $langid));
        return $query->result();
    }

    function getMunicipalitiesIds() {
        $this->db->distinct();
        $this->db->select('municipality_id');
        $this->db->from('municipalities');
        $query = $this->db->get();
        $result = $query->result();
        $res_array = array();
        foreach ($result as $key=>$val) $res_array[] = $val->municipality_id;
        return $res_array;
    }

    function getMunicipalitiesForTranslation($case_id,$lang_id){
        $query= $this->db->query("SELECT * FROM municipalities
                                    WHERE municipality_id IN (
                                        SELECT m.municipality_id FROM cases c
                                            LEFT JOIN municipalities m ON c.fkCaseMunicipalities = m.pkMunicipalityID
                                        WHERE c.pkCaseID =".$case_id.")
                                    AND municipality_lang=".$lang_id);
        return $query->result();
    }

    function getMunicipalityById($munId){
        $this->db->select('*');
        $this->db->from('municipalities');
        $this->db->where(array('pkMunicipalityID' => $munId));
        $query = $this->db->get();
        return $query->result();
    }
    function getCurrentMunicipalityModel(){
        $this->load->model('municipalities_model');
        $munModel = $this->municipalities_model->getMunicipalityById($this->session->userdata('municipality_id'));
        return $munModel;
    }


}
?>
